package top.hkyzf.study.leetcode.tree;

/**
 * description: 
 * @author zhufeng
 * @date 2024/4/3 0003 10:34
 * @version V1.0
 */
public class 找出克隆二叉树中的相同节点_1379 {
    private TreeNode node;
    public final TreeNode getTargetCopy(final TreeNode original, final TreeNode cloned, final TreeNode target) {
        dfs(original, cloned, target);
        return node;
    }

    public void dfs(TreeNode original, TreeNode cloned, TreeNode target) {
        if (original == null) {
            return;
        }
        if (node != null) {
            return;
        }
        if (original.val == target.val) {
            node = cloned;
            return;
        }
        dfs(original.left, cloned.left, target);
        dfs(original.right, cloned.right, target);
    };
}
